package com.ginmeta.common.config;

import com.mybatisflex.core.FlexGlobalConfig;
import com.mybatisflex.core.audit.AuditManager;
import com.mybatisflex.spring.boot.MyBatisFlexCustomizer;
import lombok.extern.slf4j.Slf4j;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableAspectJAutoProxy;

/**
 * @author GinMeta
 */
@Slf4j
@Configuration
@MapperScan("com.ginmeta.mapper.*")
@EnableAspectJAutoProxy(exposeProxy = true)
public class MybatisFlexConfig implements MyBatisFlexCustomizer {

    @Override
    public void customize(FlexGlobalConfig flexGlobalConfig) {
        // 进行一些列的初始化配置

        //开启审计功能
        AuditManager.setAuditEnable(true);

        //设置 SQL 审计收集器
        AuditManager.setMessageCollector(auditMessage ->
                log.info("执行sql：{} \n - 耗时：{} ms", auditMessage.getFullSql()
                        , auditMessage.getElapsedTime())
        );
    }
}
